/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bsd5ex.group1.kaokang.helper;

import com.bsd5ex.group1.kaokang.config.TableNameConstants;
import com.bsd5ex.group1.kaokang.dao.FoodDAO;
import com.bsd5ex.group1.kaokang.dao.FoodSeasonDAO;
import com.bsd5ex.group1.kaokang.dao.FoodTypeDAO;
import com.bsd5ex.group1.kaokang.dao.KitchenWareDAO;
import com.bsd5ex.group1.kaokang.dao.KitchenWareTypeDAO;
import com.bsd5ex.group1.kaokang.dao.PickingDAO;
import com.bsd5ex.group1.kaokang.dao.UnitTypeDAO;
import com.bsd5ex.group1.kaokang.model.Food;
import com.bsd5ex.group1.kaokang.model.FoodSeason;
import com.bsd5ex.group1.kaokang.model.FoodType;
import com.bsd5ex.group1.kaokang.model.KitchenWare;
import com.bsd5ex.group1.kaokang.model.KitchenWareType;
import com.bsd5ex.group1.kaokang.model.Picking;
import com.bsd5ex.group1.kaokang.model.UnitType;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author VAIO
 */
public class FoodHelper {
    
    public static void prepareAddFoodForm(HttpServletRequest request) {
        List<FoodSeason> foodSeasons = new FoodSeasonDAO().listAll();
        List<FoodType> foodTypes = new FoodTypeDAO().listAll();
        List<UnitType> unitTypes = new UnitTypeDAO().listAll();
        
        KitchenWareType pickingType = KitchenWareTypeDAO.getKitchenWareType("PICKING");
        List<KitchenWare> pickingWares = new KitchenWareDAO().query("from "+TableNameConstants.KITCHEN_WARE+
                                  " where id_kitchen_ware_type = "+pickingType.getIdKitchenWareType());
        List<Picking> pickings = new PickingDAO().listAll();
        
        request.setAttribute("foodSeasons", foodSeasons);
        request.setAttribute("foodTypes", foodTypes);
        request.setAttribute("unitTypes", unitTypes);
        request.setAttribute("pickingWares", pickingWares);
        request.setAttribute("pickings", pickings);
    }
    
    public static void addFood(String foodName, int score, int unitTypeId, int kitchenWareId, int seasonId, int foodTypeId, int pickingId) {
        
        UnitType unitType = new UnitType();
        unitType.setIdUnitType(unitTypeId);
        
        KitchenWare kitchenWare = new KitchenWare();
        kitchenWare.setIdKitchenWare(kitchenWareId);
        
        FoodSeason foodSeason = new FoodSeason();
        foodSeason.setIdFoodSeason(seasonId);
        
        FoodType foodType = new FoodType();
        foodType.setIdFoodType(foodTypeId);
        
        Picking picking = new Picking();
        picking.setIdPicking(pickingId);
                
        
        Food food = new Food(foodType, kitchenWare, foodSeason, unitType, picking, foodName, score, new Date());
        
        FoodDAO foodDAO = new FoodDAO();
        foodDAO.save( food );
        
    }
}
